package com.java.controller;

import com.java.entity.QuestionType;
import com.java.service.QuestionTypeService;
import com.java.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class QuestionTypeController extends BaseController {

    @Autowired
    private QuestionTypeService questionTypeService;

    @PostMapping("questionType/insert")
    public ResultVo insert(@RequestBody QuestionType questionType) {
        int rows = questionTypeService.insert(questionType);
        return toVo(rows);
    }

    @PostMapping("questionType/delete")
    public ResultVo delete(@RequestBody String questionTypeId) {
        if (!StringUtils.hasText(questionTypeId)){
            throw new RuntimeException("questionTypeId is null");
        }
        int rows = questionTypeService.delete(Integer.valueOf(questionTypeId));
        return toVo(rows);
    }

    @PostMapping("questionType/update")
    public ResultVo update(@RequestBody QuestionType questionType) {
        int rows = questionTypeService.update(questionType);
        return toVo(rows);
    }

    @PostMapping("questionType/selectOne")
    public ResultVo selectOne(@RequestBody String questionTypeId) {
        if (!StringUtils.hasText(questionTypeId)){
            throw new RuntimeException("questionTypeId is null");
        }
        QuestionType questionType = questionTypeService.selectOne(Integer.valueOf(questionTypeId));
        return ResultVo.success(questionType);
    }

    @PostMapping("questionType/selectAll")
    public ResultVo selectAll() {
        List<QuestionType> list = questionTypeService.selectAll();
        return ResultVo.success(list);
    }

}
